package org.one.stone.soup.grfxML.plugin.geometry;


import org.one.stone.soup.grfxML.DataPoint;
import org.one.stone.soup.grfxML.GrfxMLEngine;
import org.one.stone.soup.grfxML.plugin.SimplePlugin;
import org.one.stone.soup.grfxML.plugin.grfxMLCaster;
import org.one.stone.soup.mjdb.data.field.DataLinker;
import org.one.stone.soup.mjdb.data.field.Field;
import org.one.stone.soup.mjdb.data.field.LockException;

public class Oval extends SimplePlugin {


	public static final int ARG_RADIUSX = 0;

	public static final int ARG_RADIUSY = 1;

	public static final int ARG_STEPS = 2;

	public static final int ARG_TARGET = 3;



	org.one.stone.soup.grfxML.DataSize radiusX = new org.one.stone.soup.grfxML.DataSize(10);

	org.one.stone.soup.grfxML.DataSize radiusY = new org.one.stone.soup.grfxML.DataSize(10);

	org.one.stone.soup.grfxML.DataSize steps = new org.one.stone.soup.grfxML.DataSize(100);

	org.one.stone.soup.grfxML.DataPoints target = new org.one.stone.soup.grfxML.DataPoints();


/**
 * Oval constructor comment.
 */
public Oval (GrfxMLEngine engine){
	super(engine);
}
/**
 *
 */
public void calculate()
{
 try{
	int rX = radiusX.getValue();
	int rY = radiusY.getValue();
	int stepsV = steps.getValue();

	target.setEmpty();

	for(int loop=0;loop<stepsV;loop++)
	{
		DataPoint p = new DataPoint();
		p.setValueX( org.one.stone.soup.math.IntMath.sin(loop*360/stepsV,rX),this );
		p.setValueY( org.one.stone.soup.math.IntMath.cos(loop*360/stepsV,rY),this );
		target.add( p,this );
	}
 }catch(LockException le){}
}
/**
 * initialize method comment.
 */
public void initialize()
{
	calculate();
}
/**
 * process method comment.
 */
public void process()
{
	calculate();
}
/**
 * register method comment.
 */
public void register(DataLinker store)
{

	radiusX = grfxMLCaster.cast(radiusX,getArg(radiusX,ARG_RADIUSX,store));

	radiusY = grfxMLCaster.cast(radiusY,getArg(radiusY,ARG_RADIUSY,store));

	steps = grfxMLCaster.cast(steps,getArg(steps,ARG_STEPS,store));

	target = grfxMLCaster.cast(target,getArg(target,ARG_TARGET,store));

}
/**
 * replace method comment.
 */
public void replace(Field oldObj, Field newObj)
{

	radiusX = grfxMLCaster.replace(radiusX,oldObj,newObj);

	radiusY = grfxMLCaster.replace(radiusY,oldObj,newObj);

	steps = grfxMLCaster.replace(steps,oldObj,newObj);

	target = grfxMLCaster.replace(target,oldObj,newObj);

}
/**
 * stop method comment.
 */
public void stop() {}
}
